interface ThemeConfig {
  themeOptions: DictItem[]
  themeData: Record<string, any>
}

const themes = import.meta.glob<{ themeData: Record<string, any> }>('./themes/*.theme.ts', {
  eager: true
});

const themeData = {};

Object.keys(themes).forEach(themeKey => {
  // 配置合并规则
  mergeThemes(themeData, themes[themeKey].themeData);
});

export const themeOptions = [
  {
    label: '蓝色',
    value: '#1B71DF'
  },
  {
    label: '橙色',
    value: '#FF6600'
  }
];

const appTheme: ThemeConfig = {
  themeOptions,
  themeData
};

export const themeConfig = appTheme;

function mergeThemes(target: Record<string, any>, source: Record<string, any>) {
  Object.keys(source).forEach(key => {
    if (typeof source[key] === 'object' && source[key] !== null) {
      if (!target[key]) {
        target[key] = {};
      }
      mergeThemes(target[key], source[key]);
    }
    else {
      target[key] = source[key];
    }
  });
}
